<template>
    <el-form ref="form" :model="form" label-width="100px">
                <!--action  请求后台接口 -->
                <!-- <el-upload
                  class="avatar-uploader"
                  action="/api/consumerUpload"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload">
                  <img v-if="imageUrl" :src="imageUrl" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload> -->
                <el-form-item label="姓名">
                  <el-input v-model="form.username"></el-input>
                </el-form-item>
                <!-- <el-form-item label="性别">
                  <el-radio-group v-model="form.radio">
                    <el-radio :label="1">男</el-radio>
                    <el-radio :label="2">女</el-radio>
                  </el-radio-group>
                </el-form-item> -->
                <el-form-item label="标记">
                  <el-input v-model="form.remark"></el-input>
                </el-form-item>
                <el-form-item label="详细地址">
                  <el-input v-model="form.address"></el-input>
                </el-form-item>
                <el-form-item label="用户身份证">
                  <el-input v-model="form.identity_id "></el-input>
                </el-form-item>
                <el-form-item label="用户密码">
                   <el-input v-model="form.password "></el-input>
                </el-form-item>
                  <el-form-item label="联系电话">
                  <el-input v-model="form.phone "></el-input>
                </el-form-item>
               
                <!-- <el-form-item label="头像"> -->
                  <!-- <el-input v-model="form.head_portrait "></el-input> -->
                  <!-- <el-upload
                  class="avatar-uploader"
                  action="/api/consumerUpload"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload">
                  <img v-if="head_portrait" :src="head_portrait" class="avatar">
                  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload> 
                </el-form-item> -->
                <el-form-item>
                  <el-button type="primary" @click="update" class="submit" round>修改</el-button>
                  <el-button type="primary" round>取消</el-button>
                </el-form-item>
              </el-form>
</template>

<script>
    export default {
        created(){
          const _this=this
          axios({
             method:"get",
            url:"http://localhost:8088/users/web/selectUserByIdentityId",
            params:{identity_id:sessionStorage.getItem('identity_id')},
            data:{},
            headers:
            {
              // "Authorization":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7XCJpZFwiOjksXCJ1c2VybmFtZVwiOm51bGwsXCJwaG9uZVwiOm51bGwsXCJhZGRyZXNzXCI6bnVsbCxcInJlbWFya1wiOm51bGwsXCJhdXRob3JpdHlcIjowLFwicGFzc3dvcmRcIjpcIjExMTExMVwiLFwiaGVhZF9wb3J0cmFpdFwiOm51bGwsXCJhcHBpZFwiOm51bGwsXCJzY29wZVwiOm51bGwsXCJzdGF0ZVwiOm51bGwsXCJ3aGV0aGVyX2RlbGV0ZVwiOm51bGwsXCJpZGVudGl0eV9pZFwiOlwiMTExMTExXCIsXCJjcmVhdGVfdGltZVwiOm51bGwsXCJ1cGRhdGVfdGltZVwiOm51bGwsXCJkZWxldGVfdGltZVwiOm51bGwsXCJvcmRlcnNMaXN0XCI6bnVsbH0iLCJleHAiOjE2MDUwOTU5OTZ9.TBEM_7Ti_Mm_UB9vD236lPstsqMjWAawBaBDFSp6oN0"
            'Authorization':sessionStorage.getItem('token'),
            },
          })
          .then(function(res){
            _this.form=res.data.data.users
          })
        },
        data() {
            return {
               form: {
          // username: sessionStorage.getItem('username'),
          // remark: sessionStorage.getItem('remark'),
          // address: sessionStorage.getItem('address'),
          // identity_id:sessionStorage.getItem('identity_id'),
          // password: sessionStorage.getItem('password'),
          // phone: sessionStorage.getItem('phone'),
          username: '',
          remark:  '',
          address:  '',
          identity_id: '',
          password:  '',
          phone:  '',
          // head_portrait:'',
          // imageUrl: '',
        },
            }
        },
       
        methods: {
      //       handleAvatarSuccess(res, file) {
      //   this.imageUrl = URL.createObjectURL(file.raw);
      //   this.form.imageUrl=res;
      // },
      // beforeAvatarUpload(file) {
      //   const isJPG = file.type === 'image/jpeg';
      //   const isLt2M = file.size / 1024 / 1024 < 2;

      //   if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG 格式!');
      //   }
      //   if (!isLt2M) {
      //     this.$message.error('上传头像图片大小不能超过 2MB!');
      //   }
      //   return isJPG && isLt2M;
      // },
       update: function() {
        // axios.post("/api/updateConsumer",this.user).then(res=>{
        //   if (res.data===1){
        //     this.$router.push("/user");
        //   }else {
        //     this.$message.error(res.data.message);
        //   }
        // })
        const _this=this
          var qs=require('qs')
        axios({
            url:'http://localhost:8088/users/web/update_info',
            method:'post',
            data:qs.stringify(this.form),
            headers:
            {
              // "Authorization":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7XCJpZFwiOjksXCJ1c2VybmFtZVwiOm51bGwsXCJwaG9uZVwiOm51bGwsXCJhZGRyZXNzXCI6bnVsbCxcInJlbWFya1wiOm51bGwsXCJhdXRob3JpdHlcIjowLFwicGFzc3dvcmRcIjpcIjExMTExMVwiLFwiaGVhZF9wb3J0cmFpdFwiOm51bGwsXCJhcHBpZFwiOm51bGwsXCJzY29wZVwiOm51bGwsXCJzdGF0ZVwiOm51bGwsXCJ3aGV0aGVyX2RlbGV0ZVwiOm51bGwsXCJpZGVudGl0eV9pZFwiOlwiMTExMTExXCIsXCJjcmVhdGVfdGltZVwiOm51bGwsXCJ1cGRhdGVfdGltZVwiOm51bGwsXCJkZWxldGVfdGltZVwiOm51bGwsXCJvcmRlcnNMaXN0XCI6bnVsbH0iLCJleHAiOjE2MDUwOTU5OTZ9.TBEM_7Ti_Mm_UB9vD236lPstsqMjWAawBaBDFSp6oN0"
            'Authorization':sessionStorage.getItem('token'),
            }
        })
        .then(function(res){
         if(res.data.message=='OK'){
           alert('修改成功')
         }
        })
      },
        }
       
    }
</script>

<style scoped>

</style>
  